﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZK.BLL;
using ZK.BLL.Config;
using ZK.Entity;
using ZK.MyControl;

namespace ZK.Client.WinForm
{
    public partial class FrmRePrint : Form
    {
        public FrmRePrint()
        {
            InitializeComponent();
        }


        //BindingList<PrintData> bindinglist = new BindingList<PrintData>();
        //BindingSource bindingSource = new BindingSource();


        public PrintData PrintData { get; set; }
        private void FrmRePrint_Load(object sender, EventArgs e)
        {
            dataView1.CellDoubleClick += DataView1_CellDoubleClick;
            dxPager1.PageSize = SystemConfig.GetConfig().SystemInfoEntity.PageSize;
            AddColumns();

            LoadData();
        }

        private void DataView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataView1.CurrentCell != null && dataView1.CurrentCell.RowIndex > -1)
            {
                string id = dataView1.Rows[dataView1.CurrentCell.RowIndex].Cells["Id"].Value.ToString();
                PrintData = PrintDataBLL.Instance.Get(id);  
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        private void AddColumns()
        {

            dataView1.Columns.Add(DataGridColumnHelper.TextBoxColumnCreate(typeof(PrintData), nameof(PrintData.Id)));
            dataView1.Columns["Id"].Visible = false;
            dataView1.Columns.Add(DataGridColumnHelper.TextBoxColumnCreate(typeof(PrintData), nameof(PrintData.CustomerName)));
            dataView1.Columns.Add(DataGridColumnHelper.TextBoxColumnCreate(typeof(PrintData), nameof(PrintData.ProductName)));
            dataView1.Columns.Add(DataGridColumnHelper.TextBoxColumnCreate(typeof(PrintData), nameof(PrintData.UserPrintName)));
            dataView1.Columns.Add(DataGridColumnHelper.TextBoxColumnCreate(typeof(PrintData), nameof(PrintData.BatchNo)));
            dataView1.Columns.Add(DataGridColumnHelper.TextBoxColumnCreate(typeof(PrintData), nameof(PrintData.Other)));
            dataView1.Columns.Add(DataGridColumnHelper.TextBoxColumnCreate(typeof(PrintData), nameof(PrintData.PersonName)));
            dataView1.Columns.Add(DataGridColumnHelper.TextBoxColumnCreate(typeof(PrintData), nameof(PrintData.TemplateName)));
            dataView1.Columns.Add(DataGridColumnHelper.TextBoxColumnCreate(typeof(PrintData), nameof(PrintData.PrintDate), "yyyy-MM-dd HH:mm:ss"));

        }


        public void LoadData()
        {

            
            //string productName = txtProductName.Text.Trim();
            //string sNo = txtSNo.Text.Trim();

            //string customer = txtCustomer.Text.Trim();
            //string productName = txtModelNo.Text.Trim();
            //string modelNo = txtModelNo.Text.Trim();

            //string batchNo = txtBatchNo.Text.Trim();

            //FrmLoading.ShowWaiting(() => {
            //    DelegateAction.DoInvoke(this, () =>
            //    {


            //        int total;
            //        int pageCount;
                    
            //        var list = PrintDataBLL.Instance.GetPageList(productName, sNo, dxPager1.PageIndex, dxPager1.PageSize, out total, out pageCount);

            //        dataView1.DataSource = list;
            //        dxPager1.UpdatePageInfo(total, pageCount);
            //    });

            //});
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            LoadData();
        }

        private void btnSure_Click(object sender, EventArgs e)
        {
            if (dataView1.CurrentCell != null && dataView1.CurrentCell.RowIndex > -1)
            {
                string id = dataView1.Rows[dataView1.CurrentCell.RowIndex].Cells["Id"].Value.ToString();
                PrintData = PrintDataBLL.Instance.Get(id);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

       
    }
}
